﻿#include "discrete_face.hxx"

#include <iostream>
#include "discrete_face_cone.hxx"
#include "discrete_face_plane.hxx"
#include "discrete_face_sphere.hxx"
#include "discrete_face_spline.hxx"
#include "discrete_face_torus.hxx"
typedef std::vector<CDT::V2d<double>> point_vector;

outcome facet_face(FACE* f, double st, double nt) {
    int _typeid = f->geometry()->equation().type();

    static int i = 0;
    outcome out;
    switch (_typeid) {
    case plane_type:  // <pladef.hxx> plane_type
        // printf("PLANE\n");
        out = facet_face_plane(f, nt, st);
        break;
    case cone_type:  // <condef.hxx> cone_type
        // std::cout << "CONE" << std::endl;
        out = facet_face_cone(f, nt, st);
        break;
    case sphere_type:  // <sphdef.hxx> sphere_type
        // std::cout << "SPHERE" << std::endl;
        out = facet_face_sphere(f, nt, st);
        break;
    case torus_type:  // <tordef.hxx> torus_type
        // printf("No %d torus\n", i);
        // if(i == 36)
        out = facet_face_torus(f, nt, st);
        // i++;
        break;
    case spline_type:  // <spldef.hxx> spline_type
        // printf("SPLINE\n");
        // if(i == 0)
        out = facet_face_spline(f, nt, st);
        // i++;
        break;
    default:
        // std::cout << "GENERAL" << std::endl;
        out = facet_face_general(f, nt, st);
        break;
    }
    i++;
    if (!out.ok()) {
        printf("Error while faceting face.\n");
    }
    return outcome();
}

outcome FacetFace(FACE* f, std::unique_ptr<FacetContext>& facet_context, double st, double nt) {
    int _typeid = f->geometry()->equation().type();

    static int i = 0;
    outcome out;
    switch (_typeid) {
    case plane_type:  // <pladef.hxx> plane_type
        // printf("PLANE\n");
        out = facet_face_plane(f, nt, st);
        break;
    case cone_type:  // <condef.hxx> cone_type
        // std::cout << "CONE" << std::endl;
        out = facet_face_cone(f, nt, st);
        break;
    case sphere_type:  // <sphdef.hxx> sphere_type
        // std::cout << "SPHERE" << std::endl;
        out = facet_face_sphere(f, nt, st);
        break;
    case torus_type:  // <tordef.hxx> torus_type
        // printf("No %d torus\n", i);
        // if(i == 36)
        out = facet_face_torus(f, nt, st);
        // i++;
        break;
    case spline_type:  // <spldef.hxx> spline_type
        // printf("SPLINE\n");
        // if(i == 0)
        out = facet_face_spline(f, nt, st);
        // i++;
        break;
    default:
        // std::cout << "GENERAL" << std::endl;
        out = facet_face_general(f, nt, st);
        break;
    }
    i++;
    if (!out.ok()) {
        printf("Error while faceting face.\n");
    }
    return outcome();
}

// 该算法不会被其他文件/接口调用到，暂时不做解耦操作
outcome facet_face_general(FACE* f, double nt, double st) {
    return outcome();
}
